fix: fall back to CPU when CUDA is requested but unavailable (#216)#244
Open
ousamabenyounes wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: fall back to CPU when CUDA is requested but unavailable (#216)#244ousamabenyounes wants to merge 1 commit intomicrosoft:mainfrom
ousamabenyounes wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…ft#216) PromptCompressor defaulted to device_map="cuda" even when torch was built without CUDA support, producing "AssertionError: Torch not compiled with CUDA enabled" on Windows / CPU-only machines. The fix transparently falls back to "cpu" (with a RuntimeWarning) when "cuda" is requested but torch.cuda.is_available() is False, so the default still works out of the box on CPU-only installs. Generated by Claude Code Vibe coded by ousamabenyounes Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #216
PromptCompressordefaulted todevice_map=\"cuda\". On a CPU-only machine (e.g. Windows withtorch --index-url .../whl/cpu), instantiating the compressor immediately fails withAssertionError: Torch not compiled with CUDA enabled, forcing every user to passdevice_map=\"cpu\"manually and making the copy-paste examples in the README unusable out of the box.This PR makes
load_modelchecktorch.cuda.is_available()when a CUDA device map is requested. If CUDA isn't available, it emits aRuntimeWarningand falls back to\"cpu\"transparently, so existing code with the defaultdevice_map=\"cuda\"keeps working on GPU machines and no longer crashes on CPU-only machines.Changes
llmlingua/prompt_compressor.pydevice_map=\"cuda\"withtorch.cuda.is_available()and fall back to\"cpu\"with aRuntimeWarning. Also adds awarningsimport.tests/test_issue_216.pytorch.cuda.is_availableandAutoConfig/AutoTokenizer/AutoModel*— they run in ~4s and require no network or model download.Behavior matrix
device_maptorch.cuda.is_available()\"cuda\"(default)True\"cuda\"(default)FalseAssertionErrorRuntimeWarning\"cpu\"explicitFalseBefore submitting
Verification
Generated by Claude Code
Vibe coded by ousamabenyounes